using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace HRM.Utilities
{
    class GetProxy
    {
        internal enum RegKeyType : int
        {
            CurrentUser = 1,
            LocalMachine = 2
        }

        static void GetKeyValue(RegKeyType KeyType, string RegKey, string Name, out object Value)
        {
            RegistryKey oRegKey = null;

            switch ((int)KeyType)
            {
                case 1:
                    oRegKey = Registry.CurrentUser;
                    break;
                case 2:
                    oRegKey = Registry.LocalMachine;
                    break;
            }
            oRegKey = oRegKey.OpenSubKey(RegKey);

            Value = oRegKey.GetValue(Name);

            oRegKey.Close();
        }

        static public string GetProxyName()
        {
            string szRegKey = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings\";
            string szName = "ProxyServer";
            object szProxyAddress = "";

            GetKeyValue(RegKeyType.CurrentUser, szRegKey,
                                    szName, out szProxyAddress);

            return Convert.ToString(szProxyAddress);
        }

        static public int GetProxyStatus()
        {
            string szRegKey = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings\";
            string szName = "ProxyEnable";
            object iProxyStatus = 0;

            GetKeyValue(RegKeyType.CurrentUser,
                                  szRegKey, szName, out iProxyStatus);

            return Convert.ToInt32(iProxyStatus);
        }

    }
}